package com.baizhi.controller;

import com.baizhi.entity.Product;
import com.baizhi.service.ProductService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;

import java.util.List;
import java.util.Map;

@RestController
public class ProductController {
    @Autowired
    private ProductService ps;

    @GetMapping("prods")
    public Map<String,Object> selectPage(int page, int limit){
        PageInfo<Product> pageInfo = ps.selectPage(page, limit);
        return new HashMap(){{
            put("msg","");
            put("data",pageInfo.getList());
            put("code",0);
            put("count",pageInfo.getTotal());
        }};
    }
    @DeleteMapping("deleteId/{id}")
    public void delete(@PathVariable("id") int id){
            ps.delete(id);
    }

    @PostMapping("prods")
    public void insert(@RequestBody Product product){
        System.out.println(product);
        ps.insert(product);
    }
    @DeleteMapping("deleteIds")
    public void deleteBatchIds(@RequestBody List<Integer> ids){
        System.out.println(ids);
        ps.deleteBatchIds(ids);
    }

    @PostMapping("update")
    public void update(@RequestBody Product product){
        ps.update(product);
    }

}
